﻿<%@ WebHandler Language="C#" Class="Validate" %>

using System;
using System.Web;
using System.Web.SessionState;
using System.Drawing;
using System.Drawing.Imaging;

public class Validate : IHttpHandler, IRequiresSessionState
{

    public void ProcessRequest (HttpContext context) 
    {
        context.Response.ContentType = "image/gif";
       
        ValiManage valiManage = new ValiManage();

        string valiCode = valiManage.GenerateCheckCode();
        Bitmap b = valiManage.CreateCheckImage(valiCode);

        b.Save(context.Response.OutputStream, ImageFormat.Gif);
        
        // 将验证码存入Session中.
        context.Session["ValiCode"] = valiCode.ToString();
 
        valiManage.Dispose();

        context.Response.End();
    }
 
    public bool IsReusable 
    {
        get 
        {
            return true;
        }
    }

}